Ext.define('AmpleHarvest.objects.harvestrequest.view.HarvestRequest',
{
   extend         : 'Ext.panel.Panel',
   alias: 'widget.ampleharvest-objects-harvestrequest-view-harvestrequest',
//   id: 'harvestrequest-id',
   requires    :
   [
         'AmpleHarvest.objects.harvestrequest.view.toolbar.Top',
         "AmpleHarvest.objects.harvestrequest.view.tab.MyHarvestRequest",
         "AmpleHarvest.objects.harvestrequest.view.tab.AllHarvestRequest",
         "AmpleHarvest.eventHandler.cWindowEvents", 
         'Ext.tab.Panel'
   ],
   title       : "Harvest Request Manager",
   minHeight      : 400,
   minWidth    : 600,
   layout         : 'fit',
   iconCls        : "window-harvest-manager-icon",
   applyTo        : "Window",
   
   //Commenting out the toolbar so no new requests can be put in the "old" harvest system
   /*tbar        :
   {
      xtype : 'hr_toolbar_top'
   },*/

   initComponent  : function()
   { 
      var obj_This = this;

      Ext.QuickTips.init();

      this.tools =
      [
            {
               type  : 'refresh',
               handler  : function(event, toolEl, panel)
               {
                  this.refreshData();
               },
               scope : this
            }
      ];

      this.callParent();

      this.m_obj_SystemEvents = Ext.create(
            "AmpleHarvest.eventHandler.cWindowEvents",
            {
               m_obj_MsgBus   : obj_This,
               m_obj_Desktop  : obj_This
            }
      );

      this.m_obj_Tabs = Ext.create("Ext.tab.Panel",
            {
               // activeTab:1,
               autoLoad : false
            });
            
      Ext.Ajax.request({
       url: obj_config.C_STR_EXTERNAL_PATH+'/rest/harvestrequest/GetHarvestPermissions.php',
       method  : "GET",
       scope: this,
       success: function(response){
           var nameJsonArray = JSON.parse(response.responseText);
           // Set Permisions
           this.bool_EditOwnS1 = nameJsonArray.data.HR_EDIT_OWN_STAGE1;
           this.bool_EditOwnS2 = nameJsonArray.data.HR_EDIT_OWN_STAGE2;
           this.bool_EditAllS1 = nameJsonArray.data.HR_EDIT_ALL_STAGE1;
           this.bool_EditAllS2 = nameJsonArray.data.HR_EDIT_ALL_STAGE2;
           this.bool_DeactivateAll = nameJsonArray.data.HR_REQUEST_DEACTIVATE_ALL;
           this.bool_DeactivateOwn = nameJsonArray.data.HR_REQUEST_DEACTIVATE_OWN;
           this.bool_ViewAll = nameJsonArray.data.HR_VIEW_ALL;
           
           this.m_obj_Tabs.add(Ext.create("AmpleHarvest.objects.harvestrequest.view.tab.MyHarvestRequest", nameJsonArray) );
           this.m_obj_Tabs.add(Ext.create("AmpleHarvest.objects.harvestrequest.view.tab.AllHarvestRequest", nameJsonArray) );

           this.add(this.m_obj_Tabs);
           //Ext.getCmp('action-column-perms').items = 
       }
      });
      

   },
   
   refreshData    : function()
   {
      for (int_Tab = 0; int_Tab < this.m_obj_Tabs.items.items.length; int_Tab++)
      {
         this.m_obj_Tabs.items.items[int_Tab].refreshData();
      }
   }
});
